<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="user-scalable=no,width=device-width, initial-scale=1" id="viewport" name="viewport" initial-scale="1">

<script language="javascript" type="text/javascript" src="../js/js/baseJs.js"></script>

</head>
<body style="background:#eff6ff">

<div class="wap-my-requirements" id="myRequirements" style="display: none;">
    <div class="wap-header">我的需求
        <a class="back" onClick="javascript:window.history.back();return false;"></a>
    </div>
    <div class="my-content-bd" id="requireContent">
      <div style="min-height:101%">   
        <div class="l-content" v-for="require  in requireData">
          <div class="title"> 
              <div>标题：{{require.title}}</div>
              <div style="color:#3580e5;min-width: 1.8rem;text-align: right;">状态：{{require.status|status}}</div>
          </div>          
          <div class="content">内容：{{require.content}}</div>
        </div>
      </div>
    </div>
    <div class="wap-warning-message" v-if="messageContent">{{messageContent}}</div>
</div>
<script src="../js/js/rem_fix.js"></script>
<script src="../js/js/common.js"></script>
<script type="text/javascript">
   var token=getCookie("userToken");
   var userId=getCookie("userId");
   console.log(token)
   console.log(userId)
   var loginUrl="../userBundle/login.mobile.html"+"?"+"../userBundle/myRequirements.mobile.html";
   console.log(loginUrl)
   if(!token||!userId){
      window.location.href =loginUrl;
   }
  require(["../js/js/better_scroll"], function (BScroll) {
  var uploadPayInfoApp = new Vue({
      el: '#myRequirements', 
      data: {
           requireData:[],
           page:1,
           isDoingRefresh:false,
           isDoingloding:false,
           messageContent:''
      },
      ready:function(){
        $("#myRequirements").show();
          var url="/requirement/getPersonRequirements ";
          var data={         
              client: 1,
              category:1,
              page:this.page,
              size:20,
              token: token,
              userId: userId
            };
            console.log(data)
            pushData(url,data,function(res){
              console.log(res)
               if(res.state){
                this.requireData=res.data.requirementfeedback;
               }else{
                alert(res.message);
               }
            }.bind(this));

             this.$nextTick(function() {
                  this.loadRequirements();
             }); //回调延迟到下次 DOM 更新循环之后执行
      },
      filters:{
        status: function (key) {
            key = parseInt(key);
            var map = {
                1: "等待受理",
                2: "已受理",  
                9: "被拒",    
            };
            return map[key];
        }
      },  
      methods:{
              _initUploadOrderContentScroll:function(){
                  var requireScroll = document.getElementById('requireContent');

                  if (!this.requireLoadBScroll) {
                      this.requireLoadBScroll = new BScroll(requireScroll, {
                          click: true,
                          scrollY: true,
                          tap: true,
                          pullUpLoad: {
                              threshold: -40// 当下拉到超过顶部 距离 时，触发 pullingDown 事件
                          },
                          pullDownRefresh:{
                              threshold: 50, // 当下拉到超过顶部 50px 时，触发 pullingDown 事件
                              stop: 20// 刷新数据的过程中，回弹停留在距离顶部还有 20px 的位置
                          }
                      });

                  } else {//如果存在但就刷新并且滚回最上面
                      this.requireLoadBScroll.refresh();
                      this.requireLoadBScroll.scrollTo(0, 0);
                  }
              },
              loadRequirements:function(){
                this._initUploadOrderContentScroll();
                /*上拉刷新*/
                this.requireLoadBScroll.on('pullingDown',function(){
                    this.requireLoadBScroll.finishPullDown();
                    this.requireLoadBScroll.refresh();
                    if(this.isDoingRefresh){
                      return;
                    }
                    this.page=1;
                    this.isDoingRefresh=true;
                    var url="/requirement/getPersonRequirements ";
                    var data={         
                        client: 1,
                        category:1,
                        page:this.page,
                        size:20,
                        token: token,
                        userId: userId
                      };
                    pushData(url,data,function(res){
                      this.isDoingRefresh=false;
                      if(res.state){
                          this.requireData=res.data.requirementfeedback;                                  
                          this.showMessage("刷新成功");
                      }else{
                        alert(res.message)
                      }
                    }.bind(this))  
                }.bind(this));
                /*下拉加载*/
                this.requireLoadBScroll.on('pullingUp',function(){
                    this.requireLoadBScroll.finishPullUp();
                    this.requireLoadBScroll.refresh();
                    if(this.isDoingloding){
                      return;
                    }
                    this.page=parseInt(this.page)+1;
                    this.isDoingloding=true;
                    var url="/requirement/getPersonRequirements ";
                    var data={         
                        client: 1,
                        category:1,
                        page:this.page,
                        size:20,
                        token: token,
                        userId: userId
                      };
                      pushData(url,data,function(res){
                      this.isDoingloding=false;
                      if(res.state){
                        console.log(res.data.requirementfeedback)
                           _.each(res.data.requirementfeedback,function(requirement){
                                 this.requireData.push(requirement)
                             }.bind(this));                                

                      }else{
                        alert(res.message)
                      }
                    }.bind(this)) 
                           
                    
                }.bind(this));
            },
            showMessage:function(message){
                var _this=this;
                this.messageContent=message;
                setTimeout(function(){_this.messageContent=''}, 2500);
            }
      }
    });
});
</script>

</body>
</html>